/**
 * 静态值管理
 * @author qiuxj
 */
var staticValue = {
    init: function(dwr){
        // 增加按钮
        var addBtn = new CQCIS.Button({
            text: '增加 (<u>A</u>)',
            iconCls: 'btn_insert',
            handler: function(){
            	var obj = vStaticType.getSelectedRow();
            	if(!!obj){
            		workWin.load();
            		workWin.form.findField("staticTypeId").setValue(obj.staticTypeId);
            	}else{
            		CQCIS.msg("请选择静态值类型");
            	}
            }
        });
        
        // 修改按钮
        var editBtn = new CQCIS.Button({
            text: '修改 (<u>E</u>)',
            iconCls: 'btn_modify',
            handler: function(){
                if (grid.getSelectedRow()) {
                	workWin.load(grid.getSelectedRow()['id']);
                } else {
                    CQCIS.msg("请选择要修改的静态值");
                }
            }
        });
        
        // 员工工号信息表单
        var formMeta = [{
            id: 'id',
            field: 'id',
            desc: 'ID',
            type: 'int',
            xtype: 'hidden'
        }, {
            field: 'staticTypeId',
            desc: '静态值类型ID',
            type: 'int',
            xtype: 'hidden'
        }, {
            field: 'staticValue',
            desc: '静态值',
            type: 'int',
            obj: {
        		allowBlank: false
        	}
        }, {
            field: 'staticDesc',
            desc: '静态值描述',
            obj: {
        		allowBlank: false
        	}
        }, {
            field: 'chooseValue1',
            desc: '控制值一',
            obj: {
        		value: 'NULL'
        	}
        }, {
            field: 'chooseValue2',
            desc: '控制值二',
            obj: {
        		value: 'NULL'
        	}
        }, {
            field: 'chooseValue3',
            desc: '控制值三',
            obj: {
        		value: 'NULL'
        	}
        }, {
            field: 'state',
            desc: '状态',
            type: 'int',
            xtype: 'acombo',
            obj: {
                ds: {
                    data: [['0', '无效'], ['1', '有效']],
                    fields: ['key', 'label']
                },
                value: 1
            }
        }, {
            field: 'attr',
            desc: '属性串',
            obj: {
        		value: '0000000000'
        	}
        }];
        
        // 员工工号列表字段
        var gridMeta = [{
            id: 'id',
            desc: 'ID',
            field: 'id',
            type: 'int',
            hidden: true
        }, {
            field: 'staticTypeId',
            desc: '静态类型ID',
            type: 'int',
            hidden: true
        }, {
            field: 'staticValue',
            desc: '静态值',
            type: 'int'
        }, {
            field: 'staticDesc',
            desc: '静态值名称'
        }, {
            field: 'chooseValue1',
            desc: '控制值一'
        }, {
            field: 'chooseValue2',
            desc: '控制值二'
        }, {
            field: 'chooseValue3',
            desc: '控制值三'
        }, {
            field: 'state',
            desc: '状态',
            type: 'int',
            renderer: function(val){
                if (val == '0') {
                    return '无效';
                } 
                if (val == '1') {
                    return '有效';
                }
            }
        }, {
            field: 'attr',
            desc: '属性串'
        }];
        // 定义表单
        var workForm = new CQCIS.form.DWRForm({
            dwr: {
                load: dwr.getStaticValue,
                save: dwr.createStaticValue,
                update: dwr.updateStaticValue
            },
            metas: formMeta,
            listeners: {
                'saveafter': function(){
                    CQCIS.msg('静态值信息保存成功！');
                    grid.reload();
                }
            }
        });
        
        // 定义窗口
        var workWin = new CQCIS.form.WinForm({
            title: '静态值信息',
            width: 420,
            height: 320,
            items: workForm
        });
        
        // 代理商列表
        var grid = new CQCIS.grid.PageGrid({
            el: 'staticValue',
            title: '静态值信息',
            disabled: true,
            firstColumn: 'radio',
            dwr: {
                call: dwr.pageStaticValue
            },
            filter: {},
            sortable: true,
            metas: gridMeta,
            tbar: ['-', addBtn, '-', editBtn],
            bbar: true,
            initload: true,
            listeners: {
                'rowdblclick': editBtn.handler,
                'rowcontextmenu': function(o, rowIndex, e){
                    e.stopEvent();
                    //定义增加右键菜单
                    var addMenu = new Ext.menu.Item({
                        iconCls: 'menu_insert',
                        id: 'addMenu',
                        text: '增加',
                        handler: addBtn.handler
                    });
                    //定义修改右键菜单
                    var editMenu = new Ext.menu.Item({
                        iconCls: 'menu_modify',
                        text: '修改',
                        handler: editBtn.handler
                    });
                    //定义列表右键菜单
                    var gridMenu = new Ext.menu.Menu({
                        id: 'gridMenu',
                        items: [addMenu, editMenu]
                    });
                    gridMenu.showAt(e.getXY());
                },
                'show': function(o){
                    if (o.rendered) {
                        o.filter.staticTypeId = vStaticType.getSelectedRow().staticTypeId;
                        o.reload();
                    } else {
                        o.show.defer(100, o, [o]);
                    }
                }
            }
        });
        
        return grid;
        
    }
};
